package com.justrun.response;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * 公共结果返回实体
 * @author Chandler
 */
@Data
public class ResultEntity {
    /**
     * 状态标识
     */
//    private Boolean success;
    /**
     * 状态码
     */
    private Integer code;
    /**
     * 消息
     */
    private String message;
    /**
     * 返回数据
     */
    private Object data ;

    /**
     * 构造方法私有化，类中均为静态方法，保护属性
     */
    private ResultEntity(){

    }

    /**
     * 自定义返回成功与否
     * @param ok
     * @return
     */
 /*   public  ResultEntity success(Boolean ok){
        ResultEntity resultEntity = new ResultEntity();
        this.setSuccess(ok);
        return this;
    }
*/
    /**
     * 自定义返回消息
     * @param message
     * @return
     */
    public ResultEntity message(String message){
        this.setMessage(message);
        return this;
    }

    /**
     * 自定义返回代码
     * @param code
     * @return
     */
    public ResultEntity code(Integer code){
        this.setCode(code);
        return this;
    }

    /**
     * 自定义返回数据
     * @param dataValue
     * @return
     */
    public ResultEntity data(Object dataValue){
        this.setData(dataValue);
        return this;
    }

    /**
     * 请求成功
     * @return
     */
    public static ResultEntity ok(){
        ResultEntity resultEntity = new ResultEntity();
//        resultEntity.setSuccess(true);
        resultEntity.setCode(ResultCodeEnum.SUCCESS.getCode());
        resultEntity.setMessage(ResultCodeEnum.SUCCESS.getMesssage());
        return resultEntity;
    }


    /**
     * 请求失败返回
     * @return
     */
    public static ResultEntity fail(){
        ResultEntity resultEntity = new ResultEntity();
//        resultEntity.setSuccess(false);
        resultEntity.setCode(ResultCodeEnum.UNKOWN_ERROR.getCode());
        resultEntity.setMessage(ResultCodeEnum.UNKOWN_ERROR.getMesssage());
        return resultEntity;
    }

    public static ResultEntity excelFail(){
        ResultEntity resultEntity = new ResultEntity();
        resultEntity.setCode(ResultCodeEnum.FILE_FORMAT_ERROR.getCode());
        resultEntity.setMessage(ResultCodeEnum.FILE_CONTENT_ERROR.getMesssage());
        return resultEntity;
    }


}
